<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>系统初始化</title>
    <th:block th:include="~{common/common::commonHead}"/>
</head>
<style>
    .btn-init {
        height: 100px;
        font-size: 20px;
    }
</style>
<div>
    <div class="panel panel-primary">
        <div class="panel-heading bg-blue">
            <h1>表及数据初始化</h1>
        </div>
        <div class="widget-body">
            <form class="form-horizontal">
                <div class="form-group">
                    <label for="password" class="col-sm-2 control-label">验证密码</label>
                    <div class="col-sm-10">
                        <input type="password" class="form-control" id="password" placeholder="请输入验证">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-4">
                        <button type="button" onclick="initTable()" class="btn btn-init btn-block btn-danger">初始化表结构</button>
                    </div>
                    <div class="col-sm-4">
                        <button type="button" onclick="initData()" class="btn btn-init btn-block btn-success">初始化表数据</button>
                    </div>
                    <div class="col-sm-4">
                        <button type="button" onclick="initTableAndData()" class="btn btn-init btn-block btn-info">初始化表及数据</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

</div>
</html>
<script>
    function getPassword() {
        var $password = $("#password");
        var password = $password.val();
        if (password.length === 0) {
            $.error("请输入验证密码");
            $password.focus();
            return;
        }
        return password;
    }
    function initTable() {
        var password = getPassword();
        if (password) {
            $.doAjax("init/table", {password:password}, function () {
                $.success("表结构初始化成功")
            });
        }
    }
    function initData() {
        var password = getPassword();
        if (password) {
            $.doAjax("init/data", {password:password}, function () {
                $.success("表数据初始化成功")
            });
        }
    }
    function initTableAndData() {
        var password = getPassword();
        if (password) {
            $.doAjax("init/tableAndData", {password:password}, function () {
                $.success("表结构及数据初始化成功")
            });
        }
    }
</script>
